﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows.Input;
using CPETwit.WPFClient.Command;
using CPETwit.WPFClient.Common;

namespace CPETwit.WPFClient.ViewModel
{
    public class HeaderViewModel : INotifyPropertyChanged
    {
        #region INotifyPropertyChanged

        public event PropertyChangedEventHandler PropertyChanged;
        private void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        #endregion

        private string _search;
        public string Search
        {
            get { return _search; }
            set
            {
                _search = value;
                OnPropertyChanged("Search");
            }
        }

        private ICommand _openProfileMenuCommand;
        public ICommand OpenProfileMenuCommand
        {
            get
            {
                return _openProfileMenuCommand ??
                       (_openProfileMenuCommand = new RelayCommand(param => OpenProfileMenu(),
                                                                   param => CanOpenProfileMenu()));
            }
        }

        public ICommand OpenAboutWindowCommand
        {
            get
            {
                return new RelayCommand(param =>
                {
                    AboutWindow window = new AboutWindow();
                    window.ShowDialog();
                });
            }
        }

        private ICommand _openMainMenuCommand;
        public ICommand OpenMainMenuCommand
        {
            get
            {
                return _openMainMenuCommand ??
                       (_openMainMenuCommand = new RelayCommand(param => OpenMainMenu(),
                                                                param => CanOpenMainMenu()));
            }
        }

        private ICommand _openSuggestionsCommand;
        public ICommand OpenSuggestionsCommand
        {
            get
            {
                return _openSuggestionsCommand ??
                       (_openSuggestionsCommand = new RelayCommand(param => OpenSuggestionWindow(),
                                                                param => CanOpenSuggestionWindow()));
            }
        }

        private ICommand _logoutCommand;
        public ICommand LogoutCommand
        {
            get
            {
                return _logoutCommand ??
                       (_logoutCommand = new RelayCommand(param => Logout(),
                                                          param => CanLogout()));
            }
        }

        private bool CanLogout()
        {
            return true;
        }

        private void Logout()
        {
            DialogManager.ShowAuthentificationMenu();
        }

        private bool CanOpenSuggestionWindow()
        {
            return CommonData.LOGGED_USER != null;
        }
        private void OpenSuggestionWindow()
        {
            DialogManager.ShowUsersResearch();
        }

        private bool CanOpenProfileMenu()
        {
            return CommonData.LOGGED_USER != null;
        }
        private void OpenProfileMenu()
        {
            DialogManager.ShowProfileMenu(CommonData.LOGGED_USER);
        }

        private bool CanOpenMainMenu()
        {
            return CommonData.LOGGED_USER != null;
        }
        private void OpenMainMenu()
        {
            DialogManager.ShowMainMenu();
        }
    }
}
